using FarPoint.Win.Spread;
using FarPoint.Win.Spread.CellType;
using GrapeCity.Spreadsheet;
using System;
using System.Drawing;
using Font = GrapeCity.Spreadsheet.Font;

namespace Spread.Sparkline.Features
{
    public partial class PieSparkline : Spread.Common.Features.Sample.BaseSampleControl
    {
        public PieSparkline()
        {
            InitializeComponent();
            Name = "Pie";
            InitSpreadSheet(_fpSpread.ActiveSheet);
        }

        #region Private Methods
        private void InitSpreadSheet(SheetView sheetView)
        {
            var worksheet = sheetView.AsWorksheet();
            worksheet.Cells["A1:D1"].Merge();

            var range = worksheet.Cells["A1"];
            range.Value = "My Assets";
            range.Font.ApplyFont(new Font() { Name = "Arial", Size = 17 });
            range.VerticalAlignment = VerticalAlignment.Center;

            for (int i = 65; i < 69; i++)
            {               
                sheetView.Cells[$"{Convert.ToChar(i)}2"].BackColor = ColorTranslator.FromHtml("#E3E3E3");
            }

            worksheet.SetValue(1, 0, new object[,]
            {
                { "Asset Type", "Amount", "Diagram", "Note" },
                { "House", 120000, null, null },
                { "401k", 78000, null, null },
                { "Savings", 25000, null, null },
                { "Bonds", 15000, null, null },
                { "Stocks", 9000, null, null },
                { "Car", 7500, null, null }
            });

            worksheet.Cells["C3:C8"].Merge();
            worksheet.Cells["C3"].Formula2 = "PIESPARKLINE(B3:B8,\"#82bc00\",\"#96c63f\",\"#aacf62\",\"#bcd983\",\"#cee3a3\",\"#dfecc3\")";

            sheetView.Cells["D3"].BackColor = ColorTranslator.FromHtml("#82bc00");
            worksheet.Cells["D3"].Formula = "B3/SUM(B3:B8)";
            sheetView.Cells["D4"].BackColor = ColorTranslator.FromHtml("#96c63f");
            worksheet.Cells["D4"].Formula = "B4/SUM(B3:B8)";
            sheetView.Cells["D5"].BackColor = ColorTranslator.FromHtml("#aacf62");
            worksheet.Cells["D5"].Formula = "B5/SUM(B3:B8)";
            sheetView.Cells["D6"].BackColor = ColorTranslator.FromHtml("#bcd983");
            worksheet.Cells["D6"].Formula = "B6/SUM(B3:B8)";
            sheetView.Cells["D7"].BackColor = ColorTranslator.FromHtml("#cee3a3");
            worksheet.Cells["D7"].Formula = "B7/SUM(B3:B8)";
            sheetView.Cells["D8"].BackColor = ColorTranslator.FromHtml("#dfecc3");
            worksheet.Cells["D8"].Formula = "B8/SUM(B3:B8)";

            worksheet.Cells["D3:D8"].CellType = new PercentCellType()
            {
                DecimalPlaces = 2
            };

            worksheet.Cells["B3:B8"].CellType = new CurrencyCellType()
            {
                ShowCurrencySymbol = true,
                DecimalPlaces = 0,
                ShowSeparator = true,
                CurrencySymbol = "$"
            };

            worksheet.Rows["1"].RowHeight = 30;
            worksheet.Rows["2:8"].RowHeight = 25;
            worksheet.Columns["A"].ColumnWidth = 100;
            worksheet.Columns["B"].ColumnWidth = 100;
            worksheet.Columns["C"].ColumnWidth = 200;
        }
        #endregion
    }
}


//
//PieSparkline.Designer.cs
//



namespace Spread.Sparkline.Features
{
    partial class PieSparkline
    {
        /// <summary> 
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary> 
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Component Designer generated code

        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PieSparkline));
            this._fpSpread = new FarPoint.Win.Spread.FpSpread(FarPoint.Win.Spread.LegacyBehaviors.None, ((object)(resources.GetObject("pnlMain.Controls"))));
            this._fpSpread_Sheet1 = this._fpSpread.GetSheet(0);
            this.pnlMain.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this._fpSpread)).BeginInit();
            this.SuspendLayout();
            // 
            // pnlMain
            // 
            this.pnlMain.Controls.Add(this._fpSpread);
            this.pnlMain.Size = new System.Drawing.Size(442, 379);
            // 
            // pnlControls
            // 
            this.pnlControls.Size = new System.Drawing.Size(146, 379);
            // 
            // _fpSpread
            // 
            this._fpSpread.Dock = System.Windows.Forms.DockStyle.Fill;
            this._fpSpread.Font = new System.Drawing.Font("Calibri", 11F);
            this._fpSpread.Location = new System.Drawing.Point(0, 0);
            this._fpSpread.Name = "_fpSpread";
            this._fpSpread.Size = new System.Drawing.Size(442, 379);
            this._fpSpread.TabIndex = 0;
            // 
            // PieSparkline
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Name = "PieSparkline";
            this.Size = new System.Drawing.Size(589, 379);
            this.pnlMain.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this._fpSpread)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion

        private FarPoint.Win.Spread.FpSpread _fpSpread;
        private FarPoint.Win.Spread.SheetView _fpSpread_Sheet1;
    }
}
